// pages/orderDetails/orderDetails.js
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        modelShowC: true,
        modelShowR: true,
        confirm: "确认是否接单",
        focus: false,
        textareaTitle: "请录入不接单原因",
        itemDetail: {},
        refusedReason: ""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var itemDetail = JSON.parse(options.item)
        if (itemDetail.orders.insuredCost > 0) {
            this.setData({
                insurance: true
            })
        }
        this.setData({
            itemDetail: itemDetail,
            id: itemDetail.id,
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */

    cancel() {
        this.setData({
            modelShowC: true
        })
    },
    confirm(id) {
        var that = this
        var datas = [{
            id: that.data.id
        }]
        app.getApi.request("/api/DriversOrders/Take", datas, "POST", (res) => {
            // , driversOrdersStatusName: e.currentTarget.dataset.statusname, driversOrdersStatus: e.currentTarget.dataset.status, pickUpNums: 0 

            if (res.data.responseCode == 1000) {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000
                });
                that.setData({
                    modelShowC: true
                })
                setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    })
                }, 2000)
            } else {
                wx.showToast({
                    title: '接单失败',
                    icon: 'loading',
                    duration: 2000
                });
            }
        }, (res) => {})

    },
    cancelR() {
        this.setData({
            modelShowR: true
        })
    },
    confirmR() {
        var that = this
        var ordersList = [{ id: that.data.id }]
        if (that.data.refusedReason == "") {
            return wx.showToast({
                title: '拒接理由为空',
                icon: 'loading',
                duration: 2000
            });
        }
        app.getApi.request("/api/DriversOrders/Refused", { driversOrdersList: ordersList, refusedReason: that.data.refusedReason }, "POST", (res) => {
            if (res.data.responseCode == 1000) {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000
                });
                setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    })
                }, 2000)
            } else {
                wx.showToast({
                    title: '请求失败',
                    icon: 'loading',
                    duration: 2000
                });
            }
        }, (res) => {})
        this.setData({
            modelShowR: true
        })
    },
    bindfocus() {
        this.setData({
            focus: true
        })
    },
    bindinput(e) {
        this.setData({
            refusedReason: e.detail.value
        })
    },
    bindblur(e) {
        this.setData({
            focus: false,
            refusedReason: e.detail.value
        })
        console.log(this.data.refusedReason)
    },
    reforder() {
        this.setData({
            modelShowR: false
        })
        console.log(this.data.modelShowR)
    },
    receiving: function(e) {
        this.setData({
            modelShowC: false,
        })

    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})